package Threading2;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class ThreadDemo11 {
    public static BlockingDeque<Integer> blockingDeque = new LinkedBlockingDeque<>();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
           while (true) {
               int value = 0;
               try {
                   Thread.sleep(1000);
                   value = blockingDeque.take();
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               System.out.println("消费元素：" + value);
           }
        });
        t1.start();

        // 生产者
        Thread t2 = new Thread(() -> {
           int value = 0;
           while (true) {
               try {
                   Thread.sleep(1000);
                   blockingDeque.put(value);
                   System.out.println("生产元素：" + value);
                   value++;
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
        t2.start();
    }
}
